package com.sofeteem.ikun.model;

import java.awt.*;
import java.awt.event.KeyEvent;

public class Player {

    private int x;
    private int y;
    private int width;
    private int height;
    private int health;
    private int energy;
    private int dx;
    private int dy;

    public Player() {
        this.x = 400;
        this.y = 500;
        this.width = 20;
        this.height = 20;
        this.health = 100;
        this.energy = 0;
        this.dx = 0;
        this.dy = 0;
    }

    public void move() {
        x += dx;
        y += dy;

        if (x < 0) {
            x = 0;
        }
        if (x > 780) {
            x = 780;
        }
        if (y < 0) {
            y = 0;
        }
        if (y > 580) {
            y = 580;
        }
    }

    public void keyPressed(KeyEvent e) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT) {
            dx = -5;
        }

        if (key == KeyEvent.VK_RIGHT) {
            dx = 5;
        }

        if (key == KeyEvent.VK_UP) {
            dy = -5;
        }

        if (key == KeyEvent.VK_DOWN) {
            dy = 5;
        }
    }

    public void keyReleased(KeyEvent e) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT) {
            dx = 0;
        }

        if (key == KeyEvent.VK_RIGHT) {
            dx = 0;
        }

        if (key == KeyEvent.VK_UP) {
            dy = 0;
        }

        if (key == KeyEvent.VK_DOWN) {
            dy = 0;
        }
    }

    public Polygon getTriangle() {
        int[] xPoints = {x, x - 10, x + 10};
        int[] yPoints = {y, y + 20, y + 20};
        return new Polygon(xPoints, yPoints, 3);
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public int getHealth() {
        return health;
    }

    public int getEnergy() {
        return energy;
    }

    public void takeDamage(int damage) {
        health -= damage;
    }

    public void addEnergy(int energy) {
        this.energy += energy;
        if (this.energy > 100) {
            this.energy = 100;
        }
    }

    public void useSkill() {
        // Implement skill logic here
    }

    public Rectangle getBounds() {
        return new Rectangle(x, y, width, height);
    }

    public void setEnergy(int i) {
    }
}
